package com.J.Plane;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class PlaneActivityView extends GLSurfaceView{
	private static final String LOG_TAG = PlaneActivityView.class.getSimpleName();
	private PlaneRenderer _renderer;
	
	private float _x = 0;
	private float _y = 0;
	
	public PlaneActivityView (Context context){
		super(context);
		_renderer = new PlaneRenderer(context);
		setRenderer(_renderer);
	};
	
	public boolean onTouchEvent(final MotionEvent event){
		if (event.getAction() == MotionEvent.ACTION_DOWN){
			_x = event.getX();
			_y = event.getY();
		}
		
		if (event.getAction() == MotionEvent.ACTION_MOVE){
			final float xdiff = ( event.getX() - _x );
			final float ydiff = ( event.getY() - _y );
			queueEvent (new Runnable(){
				public void run(){
					//_renderer.setXAngle(45.0f);
					//_renderer.setYAngle(45.0f);
					_renderer.setXAngle(_renderer.getXAngle() - xdiff);
					_renderer.setYAngle(_renderer.getYAngle() + xdiff);
				}
			});
			_x = event.getX();
			_y = event.getY();
		}
		
		return true;
	}
	
}
